package exe;
import java.util.*;

class Solution {
    public static int findKthLargest(int[] nums, int k) {
        int[] arr = new int[k];
        for(int i =0;i < k;i++){
            arr[i] = nums[i];
        }
        Arrays.sort(arr);
        for(int i =k;i<nums.length;i++){
            if(nums[i] >= arr[0]){
                arr[0] = nums[k];
                proper(arr);
            }

        }
        return arr[0];
    }

    private static void swap(int[] arr,int a,int b){
        int tmp = arr[a];
        arr[a] = arr[b];
        arr[b] = tmp;
    }

    private static void proper(int[] arr){
        for(int i =0;i<arr.length-1;i++){
            if(arr[i] > arr[i+1]){
                swap(arr,i,i+1);
            }else{
                return;
            }
        }
    }

    public static void main(String[] args) {
        int[] arr = new int[] {3,2,1,5,6,4};
        findKthLargest(arr,2);
    }
}